package com.happy.ibidding.service;

import com.happy.ibidding.bean.Ask;
import com.happy.ibidding.bean.News;
import com.happy.ibidding.dao.AskRepository;
import com.happy.ibidding.dao.NewsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsService {

    final private NewsRepository newsRepository;

    @Autowired
    public NewsService(NewsRepository newsRepository) {
        this.newsRepository = newsRepository;
    }

    public News save(News news) {
        return this.newsRepository.save(news);
    }


    public List<News> viewAll() {
        return this.newsRepository.findAll();
    }

    public News view(String mongodbId) {
        return this.newsRepository.findById(mongodbId).orElse(null);
    }

    public void delete(String mongodbId){
         this.newsRepository.deleteById(mongodbId);
    }

}
